import request from './request'
import type { ApiResponse, PaginationParams, FilterParams } from '@/types'

/**
 * 客户留言接口
 */
export interface ContactMessage {
  id: number
  message_type: 'contact' | 'newsletter' | 'reseller'
  message_type_display: string
  name: string
  email: string
  message: string
  is_read: boolean
  replied_at: string | null
  created_at: string
  updated_at: string
}

/**
 * 留言统计接口
 */
export interface ContactMessageStats {
  total: number
  unread: number
  by_type: {
    [key: string]: {
      name: string
      count: number
    }
  }
}

/**
 * 获取留言列表
 */
export function getContactMessages(params?: PaginationParams & FilterParams) {
  return request<ApiResponse<ContactMessage>>({
    url: '/contact-messages/',
    method: 'get',
    params
  })
}

/**
 * 获取留言详情
 */
export function getContactMessage(id: number) {
  return request<ContactMessage>({
    url: `/contact-messages/${id}/`,
    method: 'get'
  })
}

/**
 * 更新留言
 */
export function updateContactMessage(id: number, data: Partial<ContactMessage>) {
  return request<ContactMessage>({
    url: `/contact-messages/${id}/`,
    method: 'patch',
    data
  })
}

/**
 * 删除留言
 */
export function deleteContactMessage(id: number) {
  return request({
    url: `/contact-messages/${id}/`,
    method: 'delete'
  })
}

/**
 * 标记为已读
 */
export function markContactMessageRead(id: number) {
  return request<ContactMessage>({
    url: `/contact-messages/${id}/mark_read/`,
    method: 'patch'
  })
}

/**
 * 标记为未读
 */
export function markContactMessageUnread(id: number) {
  return request<ContactMessage>({
    url: `/contact-messages/${id}/mark_unread/`,
    method: 'patch'
  })
}

/**
 * 获取统计信息
 */
export function getContactMessageStats() {
  return request<ContactMessageStats>({
    url: '/contact-messages/stats/',
    method: 'get'
  })
}

